home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / Asm / 24BitChunky / input.i < prev   
Encoding:
Text File  |  1996-08-14  |  2.5 KB  |  103 lines

  1. *-------------------------------------------------------*
  2. *           Set up input handler            *
  3. *-------------------------------------------------------*
  4.  
  5. StartHandler    LibBase exec
  6.         Call    CreateMsgPort
  7.         beq.s    .error
  8.         move.l    d0,msgport    ; save pointer to port
  9.  
  10.         move.l    d0,a0
  11.         move.l    #IOSTD_SIZE,d0
  12.         Call    CreateIORequest
  13.         beq.s    .error
  14.         move.l    d0,ioreq    ; save pointer to request
  15.  
  16.         lea.l    idname,a0    ; devName
  17.         move.l    ioreq,a1    ; iORequest
  18.         moveq.l    #0,d0        ; unitNumber
  19.         moveq.l    #0,d1        ; flags
  20.         Call    OpenDevice    ; open input.device!
  21.         tst.l    d0
  22.         bne.s    .error        ; zero = success
  23.  
  24.         move.l    ioreq,a1
  25.         move.l    #inter,IO_DATA(a1)
  26.         move.w    #IND_ADDHANDLER,IO_COMMAND(a1)
  27.         Call    DoIO        ; Install the handler!
  28.         tst.l    d0
  29.         bne.s    .error        ; zero = success
  30.  
  31.         move.l    #-1,d0        ; report success
  32.         move.w    #1,handler    ; flag it's ok to remove handler later
  33.         rts
  34.  
  35. .error        LibBase    exec
  36.         tst.l    ioreq
  37.         beq.s    .no1
  38.         move.l    ioreq,a0
  39.         Call    DeleteIORequest        ; delete iORequest if it exists!
  40.  
  41. .no1        tst.l    msgport
  42.         beq.s    .no2
  43.         move.l    msgport,a0
  44.         Call    DeleteMsgPort        ; delete port if it exists!
  45.  
  46. .no2        move.l    ioreq,a1
  47.         Call    CloseDevice        ; this is safe in >V36 even if open failed!
  48.         move.l    #0,d0            ; report error
  49.         rts
  50.  
  51. *-------------------------------------------------------*
  52. *         Close down input handler        *
  53. *-------------------------------------------------------*
  54.  
  55. StopHandler    LibBase    exec
  56.         move.l    ioreq,a1
  57.         move.l    #inter,IO_DATA(a1)
  58.         move.w    #IND_REMHANDLER,IO_COMMAND(a1)
  59.         Call    DoIO        ; remove the handler!
  60.  
  61.         move.l    ioreq,a1
  62.         move.l    $4.w,a6
  63.         Call    CloseDevice    ; close input.device
  64.  
  65.         move.l    ioreq,a0
  66.         Call    DeleteIORequest
  67.  
  68.         move.l    msgport,a0
  69.         Call    DeleteMsgPort    ; Free MsgPort
  70.         rts
  71.  
  72. *-------------------------------------------------------*
  73. *        Take care of input events        *
  74. *-------------------------------------------------------*
  75.  
  76. IHandler    move.w    ie_Qualifier(a0),d0    ; Get qualifiers
  77.         btst    #IEQUALIFIERB_LEFTBUTTON,d0
  78.         beq.s    .noleft
  79.         move.w    #1,_Quit
  80. .noleft        move.l    (a0),d0            ; Get next event
  81.         move.l    d0,a0
  82.         bne.s    IHandler
  83.         clr.l    d0    ; return NULL, no events passed on!
  84.         rts
  85.  
  86. *-------------------------------------------------------*
  87. *            Input Handler Data            *
  88. *-------------------------------------------------------*
  89.  
  90. handler        dc.w    0    
  91. _Quit        dc.w    0        ; = 1 when LMB is pressed
  92. msgport        dc.l    0        ; pointer from CreateMsgPort()
  93. ioreq        dc.l    0        ; pointer from CreateIORequest()
  94. inter        dc.l    0,0        ; LN_SUCC, LN_PRED
  95.         dc.b    NT_INTERRUPT    ; LN_TYPE
  96.         dc.b    100        ; LN_PRI
  97.         dc.l    intername    ; LN_NAME
  98.         dc.l    0        ; IS_DATA
  99.         dc.l    IHandler    ; IS_CODE
  100. intername    dc.b    "dFX Input-Handler",0
  101. idname        dc.b    "input.device",0
  102.         even
  103.